home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / Oberon4Amiga / Dialogs / DialogStaticTexts.Mod (.txt) < prev    next >
Oberon Text  |  1994-11-28  |  7KB  |  168 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 27 Oct 94
  6. Syntax10b.Scn.Fnt
  7. Chicago10.Scn.Fnt
  8. MODULE DialogStaticTexts;
  9.     (** Markus Knasm
  10. ller 22.Jun.94 - 
  11.     IMPORT DialogFrames, Dialogs, DialogTexts, Display, Files, Fonts, GraphicUtils, In, Oberon, TextFrames, Texts, Viewers;
  12.     CONST MM = 1; W* = 40; H* = 20; 
  13.     TYPE
  14.         Item* = POINTER TO ItemDesc;
  15.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  16.             fnt-: Fonts.Font;   (** the font with which the text is shown *)
  17.             s-: ARRAY 64 OF CHAR;  (** the text which is shown *) 
  18.         END;
  19.     VAR w0: Texts.Writer;
  20.     PROCEDURE (t: Item) Draw* (x, y: INTEGER; clipFrame: Display.Frame);
  21.     (** displays the object at (x, y) in frame f *)
  22.         VAR ox, oy, w, h, yh, cx, mode: INTEGER;
  23.     BEGIN
  24.         t.GetDim (ox, oy, w, h);
  25.         IF t.selected THEN mode := Display.invert ELSE mode := Display.paint END;
  26.         yh := y + (h DIV 2) - ((t.fnt.minY + t.fnt.maxY) DIV 2);
  27.         IF h - (yh - y) > t.fnt.maxY THEN GraphicUtils.DrawString (clipFrame, t.s, x+ 3, yh, w - 4, t.fnt, mode, cx) END;
  28.     END Draw;
  29.     PROCEDURE (t: Item) Copy* (VAR dup: Dialogs.Object);
  30.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  31.         VAR x: Item;
  32.     BEGIN
  33.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  34.         t.Copy^ (dup); x.fnt := t.fnt; COPY (t.s, x.s);
  35.     END Copy;
  36.     PROCEDURE (t: Item) Load* (VAR r: Files.Rider);
  37.     (** reads the object from rider r *)
  38.         VAR fntname: ARRAY 32 OF CHAR;
  39.     BEGIN t.Load^ (r); Files.ReadString (r, fntname); t.fnt := Fonts.This (fntname); Files.ReadString (r, t.s) ;
  40.     END Load;
  41.     PROCEDURE (t: Item) Store* (VAR r: Files.Rider);
  42.     (** writes the object to rider r *)
  43.     BEGIN t.Store^ (r); Files.WriteString (r, t.fnt.name); Files.WriteString (r, t.s);
  44.     END Store;
  45.     PROCEDURE (t: Item) Print* (x, y: INTEGER);
  46.     (** prints the object at printer coordinates (x, y) *)
  47.         VAR w, h, ox, oy, yh, cx: INTEGER;
  48.     BEGIN
  49.         t.GetPDim (ox, oy, w, h);
  50.         cx := (t.fnt.minY + t.fnt.maxY) DIV 2; cx := SHORT (cx * Dialogs.dUnit DIV Dialogs.pUnit);
  51.         yh := y + (h DIV 2) - cx;
  52.         IF h - (yh - y) > t.fnt.maxY THEN GraphicUtils.PrintString (t.s, x + 3, yh, w- 4, t.fnt, cx) END
  53.     END Print;
  54.     PROCEDURE (t: Item) SetFont* (fnt: Fonts.Font);
  55.     (** sets the font with which the text is shown *)
  56.     BEGIN t.Hide; t.fnt := fnt; t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
  57.     END SetFont;
  58.     PROCEDURE (t: Item) SetString* (s: ARRAY OF CHAR);
  59.     (** sets the text which is shown *)
  60.     BEGIN t.Hide; COPY (s, t.s); t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
  61.     END SetString;
  62.     PROCEDURE (t: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  63.     (** handles messages which were sent to frame f *)
  64.         VAR t1: Texts.Text;
  65.     BEGIN
  66.         t.Handle^ (f, m);
  67.         WITH f: DialogFrames.Frame DO 
  68.             WITH m: Oberon.InputMsg DO
  69.                 IF (m.id = Oberon.track) & (m.keys = {MM}) & (t.cmd[0] # 0X) THEN 
  70.                     DialogTexts.GetParText (t.par, t.panel, t1);
  71.                     t.CallCmd (f, Viewers.This (m.X, m.Y), t1) 
  72.                 END
  73.             ELSE
  74.             END
  75.         ELSE
  76.         END
  77.     END Handle;
  78.     PROCEDURE WriteToObjectStr (o: DialogTexts.Item; n: ARRAY OF CHAR);
  79.         VAR t: Texts.Text; 
  80.     BEGIN
  81.         t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
  82.     END WriteToObjectStr;
  83.     PROCEDURE (t: Item) Edit* ();
  84.     (** opens a dialog for editing the properties of the object *)
  85.         VAR on: Dialogs.Object; os, string: DialogTexts.Item; s: Item; p: Dialogs.Panel; t1: Texts.Text; fnt: Fonts.Font;
  86.     BEGIN
  87.         t.Edit^ (); p := Dialogs.editPanel;
  88.         NEW (string); string.Init; 
  89.         string.SetName ("string"); string.SetDim (245, -40, 140, 25, FALSE); p.Insert (string, FALSE); 
  90.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  91.         NEW (s); s.Init; s.SetDim (196, -36, 45, 20, FALSE); 
  92.         s.SetString ("String"); fnt := Fonts.This ("Syntax12b.Scn.Fnt"); s.SetFont (fnt);
  93.         p.Insert (s, FALSE); 
  94.         (* ---- *)  ASSERT (Dialogs.res = Dialogs.ok);
  95.         WriteToObjectStr (string, t.s); 
  96.         t1 := string.GetText (); Texts.ChangeLooks (t1, 0, t1.len, {0}, t.fnt, 0, 0);
  97.     END Edit;
  98.     PROCEDURE (t: Item) Update* (p: Dialogs.Panel);
  99.     (** sets the properties of the object to the values defined in the dialog p opened with Edit *)
  100.         VAR os: Dialogs.Object; t1: Texts.Text; r: Texts.Reader; ch: CHAR; str: ARRAY 64 OF CHAR; i: INTEGER;
  101.     BEGIN
  102.         t.Update^ (p); 
  103.         os := p.NamedObject ("string"); t1 := os(DialogTexts.Item).GetText ();
  104.         Texts.OpenReader (r, t1, 0); Texts.Read (r, ch); i := 0;
  105.         IF (r.fnt # NIL) & (r.fnt # t.fnt) THEN t.SetFont (r.fnt) END;
  106.         WHILE ~ r.eot DO 
  107.              str[i] := ch; INC (i); Texts.Read (r, ch);
  108.         END;
  109.         str[i] := 0X; 
  110.         IF str # t.s THEN t.SetString (str) END
  111.     END Update;
  112.     PROCEDURE Insert*;
  113.     (** Insert ([name] [x y w h] | ^ ) inserts a static text - item in the panel containing the caret position *)
  114.         VAR x, y, x1, y1, w, h: INTEGER; t: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; 
  115.     BEGIN 
  116.         NEW (t);  
  117.         DialogFrames.GetCaretPosition(p, x, y);
  118.         IF (p # NIL) THEN 
  119.             t.Init; t.fnt := Fonts.This ("Syntax10b.Scn.Fnt"); 
  120.             In.Open; In.Name (name);
  121.             IF ~In.Done THEN COPY ("", name); In.Open END;
  122.             COPY (name, t.s); t.SetName (name); 
  123.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  124.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  125.             ELSE
  126.                 IF w < 0 THEN w := W END;
  127.                 IF h < 0 THEN h := H END
  128.             END;
  129.             t.SetDim (x1, y1, w, h, FALSE); p.Insert (t, FALSE);
  130.         ELSE
  131.             Dialogs.res := Dialogs.noPanelSelected 
  132.         END;
  133.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogStaticTexts") END;
  134.     END Insert;
  135.     PROCEDURE SetString*;
  136.     (** SetString (str | ^) sets the string of the static text item at the caret to str *)
  137.         VAR o: Dialogs.Object; p: Dialogs.Panel; str: ARRAY 64 OF CHAR;
  138.     BEGIN 
  139.         In.Open; In.Name (str);
  140.         IF ~ In.Done THEN 
  141.             Dialogs.res := Dialogs.wrongInput
  142.         ELSE 
  143.             DialogFrames.FindObject (o, p);
  144.             IF (Dialogs.res = Dialogs.ok) & (o IS Item) THEN 
  145.                 o(Item).SetString (str); o(Item).SetFont (Fonts.This ("Syntax10b.Scn.Fnt")) 
  146.             END 
  147.         END;
  148.         IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("DialogStaticTexts") END
  149.     END SetString;
  150.     PROCEDURE GetString*;
  151.     (** writes the component s of the static text item under the caret to the log viewer *)
  152.         VAR o: Dialogs.Object; p: Dialogs.Panel; str: ARRAY 64 OF CHAR;
  153.     BEGIN
  154.         DialogFrames.FindObject (o, p);
  155.         IF Dialogs.res = Dialogs.ok THEN
  156.             IF o IS Item THEN
  157.                 COPY (o(Item).s, str);
  158.                 Texts.WriteString (w0, "String:"); Texts.WriteString (w0, str); Texts.WriteLn (w0);
  159.                 Texts.Append (Oberon.Log, w0.buf)
  160.             ELSE
  161.                 Dialogs.res := Dialogs.objectNotFound
  162.             END
  163.         END;
  164.         IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("DialogStaticTexts") END
  165.     END GetString;
  166. BEGIN Texts.OpenWriter (w0)
  167. END DialogStaticTexts.
  168.